package org.geektimes.projects.user.web.controller;

import org.eclipse.microprofile.config.Config;
import org.geektimes.configuration.facade.DefaultConfig;
import org.geektimes.web.mvc.controller.PageController;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;

/**
 * 输出 “Hello,World” Controller
 * @author lanxing
 */
@Path("/hello")
public class HelloWorldController implements PageController {

    @GET
    @Path("/world") // /hello/world -> HelloWorldController
    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) throws Throwable {
        ServletContext servletContext = request.getServletContext();
        Config config = (Config) servletContext.getAttribute(DefaultConfig.CONFIG_NAME);
        //获取JVM配置
        String runtimeName = config.getValue("java.runtime.name",String.class);
        servletContext.log("读取到配置java.runtime.name===>"+runtimeName);
        //获取操作系统环境变量
        String processors = config.getValue("PATH",String.class);
        servletContext.log("读取到配置PATH===>"+processors);
        //获取本地配置文件
        String configTest = config.getValue("test.config",String.class);
        servletContext.log("读取到配置test.config===>"+configTest);
        String applicationName = config.getValue("application.name",String.class);
        servletContext.log("读取到配置applicationName===>"+applicationName);
        return "index.jsp";
    }
}
